// src\NewProjectDlg.cpp : implementation file
//

#include "stdafx.h"
#include "DroidArena.h"
#include "include\NewProjectDlg.h"
#include "afxdialogex.h"


// CNewProjectDlg dialog

IMPLEMENT_DYNAMIC(CNewProjectDlg, CDialogEx)

CNewProjectDlg::CNewProjectDlg(CWnd* pParent /*=NULL*/)
	: CDialogEx(CNewProjectDlg::IDD, pParent)
{

}

CNewProjectDlg::CNewProjectDlg(CProject *retProj, CWnd* pParent /*=NULL*/)
	: CDialogEx(CNewProjectDlg::IDD, pParent)
{
	m_retProj = retProj;
}

CNewProjectDlg::~CNewProjectDlg()
{
}

void CNewProjectDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_PROJ_BROWSE, m_Browse);
	DDX_Control(pDX, IDC_PROJ_NAME, m_ProjectNameBox);
	DDX_Control(pDX, IDC_PROJ_FILE, m_ProjFileNameBox);
}


BEGIN_MESSAGE_MAP(CNewProjectDlg, CDialogEx)
	ON_BN_CLICKED(IDOK, &CNewProjectDlg::OnBnClickedOk)
	ON_BN_CLICKED(IDC_PROJ_BROWSE, &CNewProjectDlg::OnBnClickedProjBrowse)
END_MESSAGE_MAP()


// CNewProjectDlg message handlers

void CNewProjectDlg::OnBnClickedOk()
{
	// TODO: Add your control notification handler code here
	bool rtn = m_retProj->NewProject();
	CString tmp;
	m_ProjectNameBox.GetWindowTextW(tmp);
	m_retProj->setProjectName(tmp);
	m_ProjFileNameBox.GetWindowTextW(tmp);
	m_retProj->setProjectFileName(tmp);
	m_retProj->NewProject();
	CDialogEx::OnOK();
}

void CNewProjectDlg::OnBnClickedProjBrowse()
{
	CFileDialog fileDlg( TRUE, _T(".prj"), _T("newfile.prj"), 0, _T("All Files (*.prj)|*.prj||"), this);
	fileDlg.m_ofn.lpstrTitle = _T("Select new project name");

	if(fileDlg.DoModal() == IDOK)
	{
		m_ProjFileNameBox.SetWindowTextW(fileDlg.GetPathName());
	}
}